package flc.ast.fragment;

import android.Manifest;
import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import flc.ast.R;
import flc.ast.activity.FileScanQrActivity;
import flc.ast.activity.FileTransferActivity;
import flc.ast.databinding.FragmentTransferBinding;
import stark.common.basic.base.BaseNoModelFragment;
import stark.common.basic.event.EventStatProxy;
import stark.common.basic.utils.StkPermissionHelper;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link TransferFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class TransferFragment extends BaseNoModelFragment<FragmentTransferBinding> {


    @Override
    protected int onCreate() {
        return R.layout.fragment_transfer;
    }

    @Override
    protected void initView() {
        EventStatProxy.getInstance().statEvent1(getActivity(), mDataBinding.event5Container);

        mDataBinding.ivFileReceive.setOnClickListener(this);
        mDataBinding.ivFileTransfer.setOnClickListener(this);
    }

    @Override
    protected void onClickCallback(View v) {
        int id = v.getId();
        if (id == R.id.ivFileReceive) {//文件接收
            getReceivePermission();
        } else if (id == R.id.ivFileTransfer) {//文件传输
            getTransferPermission();
        }
    }

    @Override
    protected void initData() {

    }

    private void getTransferPermission() {
        StkPermissionHelper.permission(StkPermissionHelper.Permission.ACCESS_ALL_MEDIA)
                .reqPermissionDesc(getString(R.string.get_transfer_permission))
                .callback(new StkPermissionHelper.ACallback() {
                    @Override
                    public void onGranted() {
                        startActivity(FileTransferActivity.class);
                    }
                }).request();
    }

    private void getReceivePermission() {
        StkPermissionHelper.permission(StkPermissionHelper.Permission.ACCESS_ALL_MEDIA, Manifest.permission.CAMERA)
                .reqPermissionDesc(getString(R.string.get_receive_permission))
                .callback(new StkPermissionHelper.ACallback() {
                    @Override
                    public void onGranted() {
                        startActivity(FileScanQrActivity.class);
                    }
                }).request();
    }

}